package ccnGame;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;


import ccnGame.CCNGameNet.CCNGameCallBack;
import org.ccnx.ccn.config.ConfigurationException;
import org.ccnx.ccn.io.content.ContentEncodingException;
import org.ccnx.ccn.protocol.MalformedContentNameStringException;

public class SetNickName extends JFrame implements ActionListener{
	private static final long serialVersionUID = -8779269133035264361L;
	
	private JTextField  _textField= new JTextField(10);
	private JButton buttonStart = new JButton("Enter");
	private String nickname;
	private String space;
	public int end = -1;
	
	public SetNickName(String namespace) {
		
		space = namespace;
		
		setBounds(100, 100, 300, 100);
		Container content = getContentPane();
		JPanel pane = new JPanel();
		buttonStart.setMnemonic('E');
		JLabel label_nick = new JLabel("Input nickname : ");
		
		buttonStart.addActionListener(this);
		
		pane.add(label_nick);
		pane.add(_textField);
		pane.add(buttonStart, BorderLayout.SOUTH);
		content.add(pane);
		
	}


	public void actionPerformed(ActionEvent e2) {
		try{
			nickname = _textField.getText();
			if((null!=nickname)&&(nickname.length()>0)){
				this.setVisible(false);
				end = 1;
				
			}
			else{
				JOptionPane.showMessageDialog(this, "Click start button after typing nickname", "WARNING", JOptionPane.WARNING_MESSAGE);
			}
		}
		catch(Exception e1){
			System.err.println("Exception input : "+e1.getClass().getName()+": "+e1.getMessage());
			e1.printStackTrace();
		}

	}
	public String getNickName(){
		return nickname;
	}
	public String getSpace(){
		return space;
	}
	/*
	public static void main(String[] args){
		if(args.length!=1){
			usage();
			System.exit(-1);
		}
		
		SetNickName client;
		client = new SetNickName(args[0]);
		while(true){
			
		}
	}
	public static void usage(){
		System.err.println("usage : WordChain <ccn URl>");	
	}*/

}
